package com.mz.ozy.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.PagerAdapter;

import com.mz.ozy.bean.TwoTitleBean;

import java.util.ArrayList;

public class TitleAdapter extends PagerAdapter {

    private Context context;
    private ArrayList<TwoTitleBean.MapListBean> mList = new ArrayList<>();

    public void setData(ArrayList<TwoTitleBean.MapListBean> list) {
        this.mList = list;
    }

    public TitleAdapter(Context context, ArrayList<TwoTitleBean.MapListBean> list) {
        this.context = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        TextView textView = new TextView(context);
        container.addView(textView);
        return textView;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mList.get(position).getName();
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }

}